<template>
  <div class="bg">
    <!-- 头部标题 -->
    <Header title="系统管理—修改密码"></Header>

    <!-- 表单区 -->
    <!-- <div style="ma"></div> -->
    <el-form ref="ruleForm" :model="ruleForm" status-icon :rules="rules" label-width="120px" style="width: 600px;margin: auto;text-align:center">
      <el-form-item label="用户名">
        <el-input v-model="ruleForm.username"></el-input>
      </el-form-item>
      <el-form-item label="工号">
        <el-input v-model="ruleForm.jobNum"></el-input>
      </el-form-item>
      <el-form-item label="原密码" prop="oldPwd">
        <el-input v-model="ruleForm.oldPwd" type="password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="Pwd">
        <el-input v-model="ruleForm.Pwd" type="password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="确认密码" prop="rePwd">
        <el-input v-model="ruleForm.rePwd" type="password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">修改密码</el-button>
        <!-- <el-button @click="resetForm('ruleForm')">Reset</el-button> -->
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import moment from "moment";
import Header from "@/components/Header";

export default {
  components: {
    Header,
  },
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入新密码"));
      } else {
        if (this.ruleForm.rePwd !== "") {
          this.$refs.ruleForm.validateField("rePwd");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入新密码"));
      } else if (value !== this.ruleForm.Pwd) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      labelPosition: "right",
      ruleForm: {
        username: "",
        jobNum: "",
        oldPwd: "",
        Pwd: "",
        rePwd: "",
      },
      rules: {
        oldPwd: [{ required: true, message: "请输入原密码", trigger: "blur" }],
        Pwd: [{ required: true, validator: validatePass, trigger: "blur" }],
        rePwd: [{ required: true, validator: validatePass2, trigger: "blur" }],
      },
    };
  },
  mounted() {},
  beforeUnmount() {},
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
</style>
